from sbprice import *

s = Solution(18600, 950000)


def buy(price, size):
    s.buy(SB(price, size, 0, 0, True))


def sell(price, size):
    s.sell(SB(price, size, 0, 0, False))


def t(size, buy_price, sell_price):
    buy(buy_price, size)
    sell(sell_price, size)


def b(size, buy_price, sell_price):
    buy(buy_price, size)
    sell(sell_price, size)


def g(s, b, sp):
    t(s, b, sp)


def go(c):
    a = 430000 + (520000 + 50000) + 30000
    b = 18600 + 1200 + 800
    # c = 35.70  # 36.76
    print(
        f"""
        现值{c}
        平均{round(a / b,2)}
        偏离{round(c - a / b ,2)} , {round(round(c - a / b ,2) * b,2)}
        偏离{round((a / b - c) / (a / b) * 100, 2)}%
        修正{round((a / b - c) / c * 100 , 2)}%"""
    )
    k = c - 0.3
    g(100, 39.61 - 1.5, k)
    g(100, 39.60 - 1.5, k)
    g(100, 39.59 - 1.5, k)
    g(900, 39.54 - 1.5, k)
    g(800, 37.86, k)
    s.show()
    print("%31.2f" % s.tot)


# go(35.7)
# go(38.61)  # 20240807
# go(40.6)
# go(43.67)  # 20240927
# go(46.95)
# go(49.23)
# go(51.69)


## history

# s.buy(SB(39.06, 800, 31250.97, 2.97, True))
# s.sell(SB(39.25, 800, 31381.31, 18.69, False))
# s.buy(SB(40.55, 200, 8110.77, 0.77, True))
# s.buy(SB(40.63, 500, 20316.93, 1.93, True))
# s.sell(SB(41.27, 700, 0, 0, False))
# t(900, 41.02, 41.09)
# t(900, 40.99, 41.09)
# t(700, 42.78, 43.10)
# t(700, 42.24, 42.30)
# t(1900, 41.89, 41.99)
# t(1800, 42.40, 42.54)
# t(1900, 42.14, 42.24)
# t(1800, 42.21, 42.73)
# t(100, 41, 41.43)
# t(1900, 42.57, 42.66)
# t(1100, 42.54, 42.58)  # 9.98,11.64
# t(200, 42.91, 42.97)
# t(900, 42.91, 42.99)
# t(1100, 42.91, 42.97)  # 83.82
# t(1100, 42.89, 42.99)  # 160.73 156.79 162.04
# t(300, 42.03, 42.12)  # 18.16
# t(400, 42.03, 43.47)
# t(300, 42.02, 43.47)
# t(1200, 41.93, 43.47)
# t(1900, 43.36, 43.42)
# t(700, 41.34, 41.54)
# t(1200, 41.41, 41.60)  # 50000 1200
# t(1200, 40.92, 40.99)
# t(1200, 40.07, 40.19)
# t(1200, 39.71, 39.84)
# t(1200, 39.71, 39.85)
# t(1200, 39.17, 39.27)
# t(100, 39.42, 39.49)
# t(100, 39.42, 39.54)
# t(100, 39.42, 39.43)
# t(100, 39.50, 39.60)
# t(100, 39.50, 39.79)
# t(900, 39.56, 39.60)


a = 51.69 - 0.15
b = 20600
c = 2000
e = 29700
# print(a * b + c)
# print(2.635 * 10630)

# a = 65400
# print(a * 6.55)
a = [180, 180, 180, 285, 285, 15, 270, 105, 105, 1200, 15, 150]
b = [100, 1000, 1200, 1200, 1200, 1900, 1900, 100, 1800, 700, 700, 8000]
